/**
 * Licensed to Open-Ones Group under one or more contributor license
 * agreements. See the NOTICE file distributed with this work
 * for additional information regarding copyright ownership.
 * Open-Ones Group licenses this file to you under the Apache License,
 * Version 2.0 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a
 * copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package oog.product.biz;

import java.util.Date;
import java.util.List;

import oog.product.BeanUtil;
import oog.product.dao.ProductDao;
import oog.product.entity.Product;
import oog.product.entity.MyUser;
import oog.product.form.ProductForm;

/**
 * @author ThachLN
 *
 */
public class ProductBiz {  
    private MyUser logonUser;
    
    /**
     * @param logonUser
     */
    public ProductBiz(MyUser logonUser) {
        this.logonUser = logonUser;
    }

    /**
     * [Give the description for method].
     * @param text
     */
    public static List<Product> searchByText(String text) {
        return ProductDao.searchByText(text);
    }

    /**
     * [Give the description for method].
     * @param fromChar
     * @param toChar
     */
    public static List<Product>  searchByAlphabet(char fromChar, char toChar) {
        return ProductDao.searchByAlphabet(fromChar, toChar);
    }

    /**
     * [Give the description for method].
     * @param form
     * @return
     */
    public boolean save(ProductForm form) {
        Product product = convertForm2Entity(form);
        
        ProductDao.addProduct(product);
        return true;
    }

    /**
     * [Give the description for method].
     * @param form
     * @return
     */
    public Product convertForm2Entity(ProductForm form) {
        // Convert data from the form
        Product product = (Product) BeanUtil.convertObject(form, Product.class);
        
        product.setCreateddate(new Date());
        product.setCreatedby(logonUser.getEmail());
        
        return product;
    }

}
